package app.model;

import java.util.List;

import keter.framework.model.base.BaseModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

//@TableBind(tableName="demo")
public class Demo extends BaseModel<Demo> {
    /**
     * Logger for this class
     */
    private static final Logger logger = LoggerFactory.getLogger(Demo.class);
    
    public static final Demo dao = new Demo();
    
    public void saveBatch(List<Demo> dList){
        Db.batch(
            "insert into demo (id,name,dept,create_date) values(?,?,?,?) ",
            "id,name,dept,create_date", 
             dList, 20
        );
    }
    
    public List<Demo> findAll() {
        return dao.find("select t.id,t.name,t.dept,t.create_date from demo t");
    }
    
    public Page<Demo> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select t.id,t.name,t.dept,t.create_date", "from demo t order by id asc");
	}
    
    public List<Demo> findByName(String name) {
        return dao.find("select t.id,t.name,t.create_date from demo t where t.name=?",wrap(name));
    }
    
    @Override
    public void validate() {
        validator()
        .min("name", 1)
        .notEmpty("dept");
    }
}